package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.PaymentOpenFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

//@DefaultProperties(defaultFallback = "paymentFallbackMethod_Global")
@RestController
public class Ordercontroller {

    @Autowired
    private PaymentOpenFeignService paymentOpenFeignService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String paymentInfo_ok = paymentOpenFeignService.paymentInfo_OK(id);
        return paymentInfo_ok;
    }


//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOut_FallbackMethod",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
//    })
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
//    @HystrixCommand
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
//        int i = 10/0;
        String paymentInfo_timeOut = paymentOpenFeignService.paymentInfo_TimeOut(id);
        return paymentInfo_timeOut;
    }

    public String paymentInfo_TimeOut_FallbackMethod(@PathVariable("id") Integer id){
        return "客户端降级 ---id:" +id;
    }

    // 全局的FallbackMethod处理方法
    public String paymentFallbackMethod_Global(){
        return "全局的客户端降级的方法处理";
    }
}
